# from threading import Thread, Lock

# def wdata():
#     pass

# def rddata():
#     print("read data")

# if __name__ == "__main__":
#     #创建线程
#     t1 = Thread(tager=wdata)

#     t1.start()

#     t1.join()

# 资源竞争

# lock = Lock()

# 进程------
# 数据不共享

# 进程间的通信
# from queue import Queue

# que = Queue(3)  #最多接受3，没写或负值表示没有上限
# que.put("hahahah")
# que.put("qqqqqqqqq")
# que.put("XXXXXXXX")

# 多任务----

from threading import Thread, Lock

import time


def sing():
    print("sing")
    time.sleep(2)
    print("sing over")


def dance():
    print("dance")
    time.sleep(2)
    print("dance over")


#  多线程-----
if __name__ == "__main__":  #主程序入口
    # 创建子线程
    t0 = Thread(target=sing)
    t1 = Thread(target=dance)

    # print(t0)
    # print(t1)

    # 守护线程在start之前,主线程结束，子线程跟着结束
    t0.daemon = True
    t1.daemon = True

    t0.start()
    t1.start()

    # 阻塞 主线程 join() 在start之后

    t0.join()
    t1.join()

    print(t0.name)
    print(t1.name)
    t0.name = "001"
    t1.name = "002"

    print(t0.name)
    print(t1.name)

    print("谢幕")

# 互斥锁
# 上锁和解锁必须成对出现
# lock = Lock()
# lock.acquire()  # 上锁
# lock.release  # 解锁
